package com.ecoolex.cms.system.api.controller;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecoolex.cms.system.entity.SunrisedutyfreeApplication;
import com.ecoolex.cms.system.pojo.TokenDTO;
import com.ecoolex.cms.system.ws.CmsSystemService;
import com.ecoolex.framework.common.annotation.MethodCatchException;
import com.ecoolex.framework.common.pojo.BizResult;
import com.ecoolex.framework.common.util.Assert;
import com.ecoolex.framework.common.util.Check;


@RestController
@RequestMapping("/auth")
public class AuthController {

	@Reference
	private CmsSystemService cmsSystemService;
	
	@PostMapping("/token")
	@MethodCatchException
	public BizResult<TokenDTO> getToken(String appId, String secret) {
		Assert.isTrue(Check.notNullOrTrimEmpty(appId), 103, "AppId不存在");
		Assert.isTrue(Check.notNullOrTrimEmpty(secret), 103, "Secret不存在");

		SunrisedutyfreeApplication application = cmsSystemService.getSunrisedutyfreeApplicationByAppidAndSecret(appId, secret);
		Assert.isTrue(Check.notNull(application), 103, "参数错误");
		return BizResult.createSuccessful(cmsSystemService.createToken(application));
	}
}
